package pattern.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicStudyMember implements InvocationHandler {
    // 目标对象
    private Object targetObj;

    public DynamicStudyMember(Object targetObj) {
        this.targetObj = targetObj;
    }

    /**
     * 获取动态代理对象
     *
     * @return
     */
    public Object getProxy() {
        return Proxy.newProxyInstance(targetObj.getClass().getClassLoader(),
                targetObj.getClass().getInterfaces(), this);
    }

    /**
     * 执行代理对象的方法
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object returnObj = method.invoke(targetObj, args);
        System.out.println("订位置");
        System.out.println("召集同学");
        System.out.println("付款");
        System.out.println("开发票");
        return returnObj;
    }
}
